{extend name="main/index" /}
{block name="main"}
    {css href="/static/admin/assets/css/toastr.min.css"}

<div class="content-page">
    <div class="content">
        <div class="row">

            <div class="col-md-12">
                <div class="widget">
                    <div class="widget-header transparent">
                        <h2><strong>Sortable</strong> Table</h2>
                        <div class="additional-btn">
                            <a href="#" class="hidden reload"><i class="icon-ccw-1"></i></a>
                            <a href="#" class="widget-toggle"><i class="icon-down-open-2"></i></a>
                            <a href="#" class="widget-close"><i class="icon-cancel-3"></i></a>
                        </div>
                    </div>
                    <div class="widget-content">
                        <div class="table-responsive">
                            <table data-sortable class="table">
                                <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>商家名</th>
                                    <th>地址</th>
                                    <th>电话</th>
                                    <th>最低价</th>
                                    <th>操作</th>
                                </tr>
                                </thead>

                                <tbody>
                                {volist name="data" id="v" }
                                <tr> 
                                    <td>{$v.id}</td>
                                    <td>{$v.name}</td>
                                    <td>{$v.address}</td>
                                    <td>{$v.tel}</td>
                                    <td>{$v.price}</td>
                                    <td>
                                        <div class="btn-group btn-group-xs">
                                            <a href="{:url('admin/Goods/details')}?id={$v.id}" data-toggle="tooltip" class="btn btn-default"><i>查看详情</i></a>
                                            <a href="{:url('admin/Goods/showimg')}?id={$v.id}" data-toggle="tooltip" class="btn btn-default"><i>管理图片</i></a>
                                            <a href="{:url('admin/Goods/room')}?id={$v.id}" data-toggle="tooltip" class="btn btn-default"><i>管理商品</i></a>
                                            <a href="{:url('admin/Goods/edit')}?id={$v.id}" data-toggle="tooltip" class="btn btn-default"><i>修改</i></a>
                                            <a href="javascript:;" data-toggle="tooltip" data-id="{$v.id}" class="btn btn-default del-btn"><i>删除</i></a>
                                        </div>
                                    </td>
                                </tr>
                                {/volist}
                                </tbody>
                            </table>
                            {$data->render()}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{js href="/static/admin/assets/js/jquery.min.js"}
{js href="/static/admin/assets/js/toastr.min.js"}

<script>
    $(function () {
        // 设置弹框参数
        toastr.options = {
            closeButton: true,// 是否显示关闭按钮
            progressBar: true,// 实现显示计时条
            timeOut: "3000",  // 自动关闭时间
            positionClass: "toast-bottom-left" // 提示位置
            // toast-top-full-width 顶端，宽度铺满整个屏幕
            // toast-top-right  顶端右边
        };

        // 触发删除用户
        $('.del-btn').click(function () {
            var ac_id = $(this).attr('data-id');
            console.log('删除操作,ID:', ac_id);
            if (confirm('你确定要[删除]吗?!')) {
                var obj = $(this).closest('tr');
                delAjax(ac_id, obj); // 执行AJAX删除
            }
        });
    });


    // 执行AJAX删除
    function delAjax(id, obj) {
        console.log(obj);
        $.ajax({
            type: 'delete',
            url: '/goods/' + id,
            dataType: 'json',
            success: function (data) {
                console.log(data);
                if (data.status) {
                    toastr.success(data.info);
                    // 将该条目删除掉
                    obj.remove();
                } else {
                    toastr.error(data.info, 'FBI WARING:');
                }
            },
            error: function () {
                alert('AJAX操作失败');
            }
        });
    }


</script>
{/block}